package com.naiterui.ehp.bs.doctor.dao.impl;

import com.naiterui.ehp.bp.domain.DrSpecPatient;
import com.naiterui.ehp.bs.doctor.dao.IDrSpecPatientDao;
import com.naiterui.ehp.bs.doctor.repository.IDrSpecPatientRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 医生特别关注患者持久层实现
 *
 * @author Amber
 * @since 1.0.0
 */
@Component
public class AdDrSpecPatientDaoImpl  implements IDrSpecPatientDao {

    @Autowired
    private IDrSpecPatientRepository drSpecPatientRepository;

    @Override
    public void saveOrUpdate(DrSpecPatient specPatient) {

        if(specPatient.getId() == null){
            drSpecPatientRepository.save(specPatient);
        } else {
            drSpecPatientRepository.update(specPatient);
        }
    }

    @Override
    public List<Long> getSpecPatientIdsByDoctorId(Long doctorId) {
        List<DrSpecPatient> result = drSpecPatientRepository.findByDoctorId(doctorId);
        return result.stream().map(DrSpecPatient::getPatientId).collect(Collectors.toList());
    }

    @Override
    public DrSpecPatient getSpecPatient(Long doctorId, Long patientId) {
        return drSpecPatientRepository.findFirstByDoctorIdAndPatientId(doctorId, patientId);
    }

    @Override
    public void deleteSpecPatient(DrSpecPatient specPatient) {
        drSpecPatientRepository.delete(specPatient);
    }

}
